package com.efounder.utils;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2019/1/4 10:32
 * @desc :  很多外国语言用DecimalFormat格式化后的小数点变为逗号，无法转换，继承DecimalFormat，强制使用小数点
 * @version: 1.0
 */
public class CommonDecimalFormat extends DecimalFormat {
    public CommonDecimalFormat() {
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        init(dfs);
    }

    public CommonDecimalFormat(String pattern) {
        super(pattern);
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        init(dfs);
    }

    public CommonDecimalFormat(String pattern, DecimalFormatSymbols symbols) {
        super(pattern, symbols);
        init(symbols);
    }

    private void init(DecimalFormatSymbols dfs) {
        //设置于小数分隔符
        dfs.setDecimalSeparator('.');
        //设置千分位分隔符
        dfs.setGroupingSeparator(',');
        this.setDecimalFormatSymbols(dfs);
    }
}
